package cn.edu.scau.cmi.chenyuanying.multiton;

import java.util.ArrayList;
import java.util.List;

public class Marshal {
	private static List<Marshal> instances;
	private final static int COUNT = 10;
	private String name;
	private Marshal(String name) {
		this.name = name;
	}
	
	public static boolean insert(String name) {
		if(instances == null) instances = new ArrayList<>();
		if(instances.size() < COUNT) {
			instances.add(new Marshal(name));
			return true;
		}
		return false;
	}
	
	public static List<Marshal> getInstances() {
		return instances;
	}
	
	@Override 
	public String toString() {
		return name + " " + getClass().getName() + '@' + hashCode();
	}
}

